package com.sbw;

import ezvcard.VCard;

import java.io.*;
import java.util.ArrayList;
import java.util.List;

/**
 * Hello world!
 *
 */
public class App
{

    public static void main( String[] args ) throws IOException {

        // 定义日期 批次 备注
        String date = "210711";
        String from = "gxj";
        String note = "";

        // 输出文件位置
        String fileName = "vcard" + "-" + from + "-" + date + ".vcf";
        File outFile = new File("E:\\IDEAWorkSpace\\ConvertNum2VCard\\src\\main\\java\\com\\sbw\\file\\" + fileName);

        List<VCard> vCards = new ArrayList<>();

        // 原始数据
        File localFile = new File("E:\\IDEAWorkSpace\\ConvertNum2VCard\\src\\main\\java\\com\\sbw\\file\\PhoneNumbers.txt");
        FileReader fileReader = new FileReader(localFile);
        BufferedReader bw = new BufferedReader(fileReader);
        String s;
        int line = 0;
        while((s = bw.readLine()) != null){
            line++;
            // 解析手机号 拼接名称
            String[] arrays = s.split("-");
            String decryptNum = DesUtil.decrypt(arrays[1]);
            String name = " " + arrays[0] + "-" + from + "-" + date;
            String email = "xxxxxx@163.com";
            UserInfo userInfo = new UserInfo(name, email, decryptNum, note);

            // 生成VCard信息
            VCard vCard = VCardUtil.getVCardByUser(userInfo);
            vCards.add(vCard);

        }

        // 数据落文件
        VCardUtil.write2File(outFile, vCards);

        // 关闭流
        bw.close();
        fileReader.close();

        System.out.println("SUCCESS，成功生成" + line + "条数据到文件");

    }

}
